<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Photographmod extends CI_Model 
{

    function __construct()
    {
        parent::__construct();
    	$this->load->database();

	}
	
//################## commun function################################
	public function updatetemplate($tablename,$data,$where)
		{
				
			$str = $this->db->update_string($tablename, $data, $where);
			
			$query = $this->db->query($str);
			//print_r($query);
			
		}	
		
	public function insertetemplate($tablename,$data)
		{
				
			$str = $this->db->insert_string($tablename, $data);
			$query = $this->db->query($str);
			$idinsert=$this->db->insert_id();
			return $idinsert;
			
		}	

	public  function getoption($code)
	{
		$query = $this->db->query("SELECT  * FROM options where code='$code' LIMIT 0, 1 ");
		$value_arr=$query->result_array();
		if(count($value_arr)==1)
		{
			return $value_arr[0]["content"];
		}else 
		
		return "";
	
		
	}	
		
//######################### end commun function###########################


	public function getpgraphassigned($pgraphid)
	{
		$query=$this->db->query("select sho.User_idUser as photographid, u.name as username, u.idUser,app.idappointments, app.idgooglecalendor, app.casefollowups_idcase, app.stores_idstores, app.coments, app.forfait_idforfait, app.date, app.starttime, app.endtime
,cf.reminder, cf.longtimefollowups,companyname, address, tele, fax, city, contactperson, contactpersonemail, ff.name as forfaitname, prix, ff.qtybull, ff.comments, ff.timeshow,sho.idshooting
from shooting as sho inner join   appointments as app  on  sho.appointments_idappointments= app.idappointments inner join casefollowups as cf on cf.idcase= app.casefollowups_idcase inner join clients as cl on cl.idclients=cf.clients_idclients
inner join forfait as ff on ff.idforfait=app.forfait_idforfait  inner join User as u on u.idUser= cf.User_idUser 
where app.starttime >=now()  - INTERVAL 30 DAY  and app.starttime <= now()+ INTERVAL 30 DAY and statusshooting_idstatusshooting=1  and sho.User_idUser=$pgraphid order by  app.starttime");
		
		return $query->result_array();
	}
	
	
	public function  getpgraphshowdone($pgraphid)
	{
		$query=$this->db->query("select sho.User_idUser as photographid, u.name as username, u.idUser,app.idappointments, app.idgooglecalendor, app.casefollowups_idcase, app.stores_idstores, app.coments, app.forfait_idforfait, app.date, app.starttime, app.endtime
,cf.reminder, cf.longtimefollowups,companyname, address, tele, fax, city, contactperson, contactpersonemail, ff.name as forfaitname, prix, ff.qtybull, ff.comments, ff.timeshow,sho.idshooting
from shooting as sho inner join   appointments as app  on  sho.appointments_idappointments= app.idappointments inner join casefollowups as cf on cf.idcase= app.casefollowups_idcase inner join clients as cl on cl.idclients=cf.clients_idclients
inner join forfait as ff on ff.idforfait=app.forfait_idforfait  inner join User as u on u.idUser= cf.User_idUser 
where app.starttime >=now() - INTERVAL 30 DAY and app.starttime <= now()+INTERVAL 30 DAY and statusshooting_idstatusshooting=2 and sho.User_idUser=$pgraphid order by  app.starttime");
		
		return $query->result_array();
	}


	public function  getpgraphpicasa($pgraphid)
	{
		$query=$this->db->query("select sho.User_idUser as photographid, u.name as username, u.idUser,app.idappointments, app.idgooglecalendor, app.casefollowups_idcase, app.stores_idstores, app.coments, app.forfait_idforfait, app.date, app.starttime, app.endtime
,cf.reminder, cf.longtimefollowups,companyname, address, tele, fax, city, contactperson, contactpersonemail, ff.name as forfaitname, prix, ff.qtybull, ff.comments, ff.timeshow,sho.idshooting
from shooting as sho inner join   appointments as app  on  sho.appointments_idappointments= app.idappointments inner join casefollowups as cf on cf.idcase= app.casefollowups_idcase inner join clients as cl on cl.idclients=cf.clients_idclients
inner join forfait as ff on ff.idforfait=app.forfait_idforfait  inner join User as u on u.idUser= cf.User_idUser 
where app.starttime >=now() - INTERVAL 30 DAY and app.starttime <= now()+INTERVAL 30 DAY and statusshooting_idstatusshooting=3 and sho.User_idUser=$pgraphid order by  app.starttime");
		
		return $query->result_array();
	}	
	
	
	
  public  function getlistphotograph()
  {
  	$query=$this->db->query("select iduser,name from User where role='photo'");
	return $query->result_array();
  }	
	
public function getliststatusshooting()
  {
  	$query=$this->db->query("SELECT * FROM statusshooting");
	return $query->result_array();
  }	
  
  

  
  
//get appointment by idappointement

	public function getuserappointbyidpointement($idappointments)
	{
		$query=$this->db->query("select app.idappointments, app.idgooglecalendor, app.casefollowups_idcase, app.stores_idstores, app.coments, app.forfait_idforfait, app.date, app.starttime, app.endtime
,cf.reminder, cf.longtimefollowups,companyname, address, tele, fax, city, contactperson, contactpersonemail, ff.name as forfaitname, prix, ff.qtybull, ff.comments, ff.timeshow,u.name as username, u.idcolor
from appointments as app inner join casefollowups as cf on cf.idcase= app.casefollowups_idcase inner join clients as cl on cl.idclients=cf.clients_idclients
inner join forfait as ff on ff.idforfait=app.forfait_idforfait inner join User as u on u.idUser= cf.User_idUser  where app.idappointments =$idappointments");
		
		return $query->result_array();
	}
  
	

	
}
